package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.UUID;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.InsuranceMapper;
import com.ruoyi.system.domain.Insurance;
import com.ruoyi.system.service.IInsuranceService;
import com.ruoyi.common.core.text.Convert;

import javax.annotation.Resource;

/**
 * 学生保险Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-11-08
 */
@Service
public class InsuranceServiceImpl implements IInsuranceService 
{
    @Resource
    private InsuranceMapper insuranceMapper;

    /**
     * 查询学生保险
     * 
     * @param insuranceId 学生保险主键
     * @return 学生保险
     */
    @Override
    public Insurance selectInsuranceByInsuranceId(String insuranceId)
    {
        return insuranceMapper.selectInsuranceByInsuranceId(insuranceId);
    }

    /**
     * 查询学生保险列表
     * 
     * @param insurance 学生保险
     * @return 学生保险
     */
    @Override
    public List<Insurance> selectInsuranceList(Insurance insurance)
    {
        return insuranceMapper.selectInsuranceList(insurance);
    }

    /**
     * 新增学生保险
     * 
     * @param insurance 学生保险
     * @return 结果
     */
    @Override
    public int insertInsurance(Insurance insurance)
    {
        if (insurance.getInsuranceId() == null||"".equals(insurance.getInsuranceId())){
            String uuid = UUID.randomUUID().toString();
            String id="PHID"+ DateUtils.dateTime()+uuid.substring(uuid.length()-5,uuid.length()-1);
            insurance.setInsuranceId(id);
        }
        return insuranceMapper.insertInsurance(insurance);
    }

    /**
     * 修改学生保险
     * 
     * @param insurance 学生保险
     * @return 结果
     */
    @Override
    public int updateInsurance(Insurance insurance)
    {
        return insuranceMapper.updateInsurance(insurance);
    }

    /**
     * 批量删除学生保险
     * 
     * @param insuranceIds 需要删除的学生保险主键
     * @return 结果
     */
    @Override
    public int deleteInsuranceByInsuranceIds(String insuranceIds)
    {
        return insuranceMapper.deleteInsuranceByInsuranceIds(Convert.toStrArray(insuranceIds));
    }

    /**
     * 删除学生保险信息
     * 
     * @param insuranceId 学生保险主键
     * @return 结果
     */
    @Override
    public int deleteInsuranceByInsuranceId(String insuranceId)
    {
        return insuranceMapper.deleteInsuranceByInsuranceId(insuranceId);
    }
}
